/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.seedwill.common.dozer.reloading;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.dozer.util.MappingValidator;

/**
 * A persistent configuration loaded and saved to a file.
 *
 * @author Emmanuel Bourg
 * @version $Revision: 1.1 $, $Date: 2009/08/10 05:15:30 $
 * @since 1.0-rc2
 */
public class FileConfiguration
{

	private String fileName;
	
	
	public FileConfiguration(URL url) {
		super();
		URL = url;
		this.file = ConfigurationUtils.fileFromURL(this.URL);
	}

	public FileConfiguration(File file) {
		super();
		this.file = file;
		try {
			this.URL = ConfigurationUtils.toURL(file);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public FileConfiguration(String fileName) {
		super();
		this.fileName = fileName;
		this.URL = MappingValidator.validateURL(this.fileName);
		this.file = ConfigurationUtils.fileFromURL(this.URL);
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	private File file;
	
	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public URL getURL() {
		return URL;
	}

	public void setURL(URL url) {
		URL = url;
	}

	private URL  URL;

    /** Holds a reference to the reloading strategy.*/
    protected ReloadingStrategy strategy;

	public ReloadingStrategy getStrategy() {
		return strategy;
	}

	public void setStrategy(ReloadingStrategy strategy) {
		this.strategy = strategy;
	}

	public void setReloadingStrategy(
			ReloadingStrategy strategy) {
        this.strategy = strategy;
        strategy.setConfiguration(this);
        strategy.init();
	}
 


}
